﻿using BLL.Webmonitor;
using DEL.Webmonitor;
using Hangfire;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;

namespace Web.Areas.Webmonitor.Controllers
{
    [Area("Webmonitor")]
    public class HangfireController: Controller
    {
        GetInfos _getInfos = new GetInfos();

        [Authorize(Roles = "super")]
        public void AddHangfire(int websiteJKid)
        {
            WebsiteJKService _wjks = new WebsiteJKService();
            var wjk = _wjks.GetEntityById(websiteJKid);
            RecurringJob.AddOrUpdate(wjk.WebsiteId + "_" + wjk.BigclassName, () => Dowork(wjk), Cron.MinuteInterval(wjk.JkTime));
        }

        [Authorize(Roles = "super")]
        public string Dowork(WebsiteJK wjk)
        {
            try
            {
                List<InfoOriginal> tempListO = _getInfos.GetListOriginal(wjk);      //获取原始信息                    
                List<InfoHit> tempListHit = _getInfos.GetListHit(tempListO);    //获取命中信息
                return "成功获取，原始信息：" + tempListO.Count + ",命中信息：" + tempListHit.Count;
            }
            catch (Exception ex)
            {
                return "出错了：" + ex;
            }
        }

        public int Test(string url)
        {
            return GetInfos.test(url);
        }

    }
}
